/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.appweb;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.goods.entity.*;
import com.jeesite.modules.goods.service.*;
import com.jeesite.modules.jdProduct.entity.DelayOrder;
import com.jeesite.modules.jdProduct.service.DelayOrderService;
import com.jeesite.modules.jdProduct.vo.OnOrderVo;
import com.jeesite.modules.jdProduct.vo.POrderVo;
import com.jeesite.modules.pay.totalPay.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.cache.JedisUtils;
import com.jeesite.common.responseReturn.entity.ResultObject;
import com.jeesite.common.responseReturn.utils.CommonUtils;
import com.jeesite.common.responseReturn.web.Render;
import com.jeesite.common.utils.KdniaoTrackQueryAPI;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.config.MyProps;
import com.jeesite.modules.jdProduct.utils.ProductPoolUtils;
import com.jeesite.modules.recovery.entity.ZtWL;
import com.jeesite.modules.util.TTest;
import com.jeesite.modules.xcxAdmin.entity.ZtAdmin;
import com.jeesite.modules.xcxAdmin.service.ZtAdminService;

/**
 * 测试数据Controller
 *
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${frontPath}/ztOrder")
public class AppZtOrderController extends BaseController {

    @Autowired
    private ZtOrderService ztOrderService;
    @Autowired
    private ZtColorService ztColorService;
    @Autowired
    private ZtSpecificationsService ztSpecificationsService;
    @Autowired
    private ZtGoodsOrderService ztGoodsOrderService;
    @Autowired
    private ZtGoodsService ztGoodsService;
    @Autowired
    private ZtTrolleyService ztTrolleyService;

    @Autowired
    private MyProps myProps;
    @Autowired
    private ZtQuanselfService ztQuanselfService;
    @Autowired
    private ZtQuanService ztQuanService;
    @Autowired
    private ZtAdminService ztAdminService;

    @Autowired
    private DelayOrderService delayOrderService;
    @Autowired
    private ZtFinancialService ztFinancialService;


    @ResponseBody
    @RequestMapping(value = "cancelProductOrder")
    public void cancelProductOrder(HttpServletRequest request, HttpServletResponse response) {
        String paramStr = CommonUtils.getParams(request);
        ResultObject res = new ResultObject();
        JSONObject jo = JSONObject.parseObject(paramStr);
        String order = jo.getString("order");
        String adminid = jo.getString("adminid");
        if (StringUtil.isEmpty(order) || StringUtil.isEmpty(adminid)) {
            res.setMsg("参数异常！");
            res.setResult(400L);
            Render.renderString(response, res);
            return;
        }
        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setOrder(order);
        ztOrder = ztOrderService.findByOrder(ztOrder);
        if(ztOrder==null){
            res.setMsg("内部参数异常！");
            res.setResult(400L);
            Render.renderString(response, res);
            return;
        }
        DelayOrder delayOrder = new DelayOrder();
        delayOrder.setOrder(order);
        delayOrder = delayOrderService.findByDelayOrder(delayOrder);

        if (delayOrder == null) {
            if (System.currentTimeMillis() >(ztOrder.getCreateDate().getTime()+3550000L)){
                res.setMsg("已过订单犹豫期、如需取消请选择售后服务！");
                res.setResult(400L);
                Render.renderString(response, res);
                return;
            }
        }else {
            if (System.currentTimeMillis() > delayOrder.getExpireTime()) {
                res.setMsg("已过订单犹豫期、如需取消请选择售后服务！");
                res.setResult(400L);
                Render.renderString(response, res);
                return;
            }
        }
        ZtAdmin ztAdmin = ztOrder.getZtAdmin();
        if (!ztAdmin.getId().equals(adminid)) {
            res.setMsg("非法操作！");
            res.setResult(400L);
            Render.renderString(response, res);
            return;
        }
        ZtGoodsOrder ztGoods = new ZtGoodsOrder();
        ztGoods.setOrder(order);
        List<ZtGoodsOrder> goodsOrders = ztGoodsOrderService.findByOrder(ztGoods);

        ztOrder.setOrderstatus("4");
        try {
            ztAdmin = ztAdminService.get(ztAdmin);
            if(ztAdmin==null){
                res.setMsg("非法操作！");
                res.setResult(400L);
                Render.renderString(response, res);
                return;
            }
            for (ZtGoodsOrder goodsOrder : goodsOrders) {
                goodsOrder.setOrderstatus("6");
                ztGoodsOrderService.update(goodsOrder);
              /*  balanceDetail(2,goodsOrder);*/
                forBalance(goodsOrder);
            }
            ztAdmin.setCashAmount(ztAdmin.getCashAmount() + (ztOrder.getOrigPrice() + ztOrder.getFreight()));
            ztAdmin.setAmount(ztAdmin.getAmount() - (ztOrder.getBalance()));

            ztAdminService.update(ztAdmin);
            if(delayOrder!=null) {
                delayOrder.setStatus("3");
                delayOrderService.updateStatus(delayOrder);
            }
            ztOrderService.update(ztOrder);
        } catch (Exception e) {
            e.printStackTrace();
        }
        res.setResult(200L);
        res.setMsg("取消成功!");
        Render.renderString(response, res);

    }
  /*  private void balanceDetail(Integer type, ZtGoodsOrder ztGoodsOrder) {
        switch (type) {
            case 1:
                lessBalance(ztGoodsOrder, "-￥","3");
                break;
            case 2:
                lessBalance(ztGoodsOrder, "+￥","5");
                break;
            default:
                System.out.println("出错了");
        }
    }

    private void lessBalance(ZtGoodsOrder ztGoodsOrder,String str,String type) {
        if(ztGoodsOrder.getBalance() >0D){
            ZtFinancial ztFinancial=new ZtFinancial();
            ztFinancial.setType(type);
            ztFinancial.setContent("商品订单-"+ztGoodsOrder.getZtGoods().getTitle());
            ztFinancial.setZtAdmin(ztGoodsOrder.getZtAdmin());
            ztFinancial.setPricestr(str + ztGoodsOrder.getBalance());
            ztFinancial.setPrice(ztGoodsOrder.getBalance());
            ztFinancial.setCreateDate(new Date());
            ztFinancial.setUsername(ztGoodsOrder.getZtAdmin().getName());
            ztFinancial.setHeadimgurl(ztGoodsOrder.getZtAdmin().getHeadimgurl());
            ztAdminService.setNames();
            ztFinancialService.save(ztFinancial);
        }
    }*/

    /**
     * 取消订单
     */
    @ResponseBody
    @RequestMapping(value = "cancelOrder")
    public void cancelOrder(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String orderid = jo.getString("orderid");
        String state = "0";//0是手动取消   1是超时
        if (jo.get("state") != null) {
            state = jo.get("state").toString();
        }
        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setId(orderid);

        ztOrder = ztOrderService.get(ztOrder);
        if (ztOrder != null && StringUtils.isNotBlank(ztOrder.getId())) {
            ZtAdmin ztAdmin = ztOrder.getZtAdmin();
            ztAdmin = ztAdminService.get(ztAdmin);

            if ("0".equals(ztOrder.getOrderstatus())) {//待付款
                double bala = ztOrder.getBalance();
                if (bala > 0) {
                    ztAdmin.setAmount(ztAdmin.getAmount() - bala);
                    ztAdmin.setCashAmount(ztAdmin.getCashAmount() + bala);
                    ztAdminService.save(ztAdmin);
                }
                if ("1".equals(state)) {
                    ztOrderService.updateOrderstatusOuttime(ztOrder);
                } else {
                    ztOrderService.updateOrderstatus(ztOrder);
                }
            }

        }

        ResultObject res = new ResultObject();

        res.setResult(200L);
        Render.renderString(response, res);

    }

    /**
     * 确认收货 （已完成订单）
     */
    @ResponseBody
    @RequestMapping(value = "overOrder")
    public void overOrder(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String orderid = jo.getString("orderid");
        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ztGoodsOrder.setId(orderid);

        ztGoodsOrder = ztGoodsOrderService.get(ztGoodsOrder);

        if (ztGoodsOrder != null) {
            ztGoodsOrder.setOrderstatus("3");
            ztGoodsOrder.setSalestatus("1");
            ztGoodsOrderService.updateOrderstatus(ztGoodsOrder);
            int spotid = ztGoodsOrder.getSpotid();
            if (spotid == 1) {//京东
                if (StringUtils.isNotBlank(ztGoodsOrder.getChannelorder())) {
                    ProductPoolUtils.confirmreceived(ztGoodsOrder.getChannelorder());
                }
            }
        }
        ResultObject res = new ResultObject();

        res.setResult(200L);
        Render.renderString(response, res);

    }

    /**
     * 删除订单
     */
    @ResponseBody
    @RequestMapping(value = "deleteOrder")
    public void deleteOrder(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String orderid = jo.getString("orderid");
        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setId(orderid);
        ztOrderService.delete(ztOrder);

        ResultObject res = new ResultObject();

        res.setResult(200L);
        Render.renderString(response, res);

    }

    /**
     * 待发货列表
     */
    @ResponseBody
    @RequestMapping(value = "notPayList")
    public void notPayList(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");
        String orderstatus = "0";

        if (jo.get("orderstatus") != null) {
            orderstatus = jo.get("orderstatus").toString();
        }

        String pageNum = "1";
        if (jo.get("pageNum") != null) {
            pageNum = jo.get("pageNum").toString();
        }

        ResultObject res = new ResultObject();
        ZtOrder ztOrder = new ZtOrder();
        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ztOrder.setZtAdmin(ztAdmin);
        ztOrder.setPageNum((Integer.valueOf(pageNum) - 1) * 15);
        ztOrder.setOrderstatus(orderstatus);

        List<ZtOrder> orderList = ztOrderService.findMh(ztOrder);

        if (orderList == null) {
            orderList = new ArrayList<ZtOrder>();
        }
        if (orderList.size() > 0) {
            for (ZtOrder zo : orderList) {
                String goods = zo.getGoods();

                if (StringUtils.isNotBlank(goods)) {
                    List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();

                    JSONArray goodsArr = JSONArray.parseArray(goods);

                    for (int i = 0; i < goodsArr.size(); i++) {
                        JSONObject jno = goodsArr.getJSONObject(i);

                        ZtGoods ztGoods = new ZtGoods();
                        ztGoods.setId(jno.getString("goodsid"));

                        ZtGoods ztg = ztGoodsService.get(ztGoods);
                        ztGoods.setTitle(ztg.getTitle());
                        ZtColor ztColor = new ZtColor();
                        ztColor.setId(jno.getString("colorid"));
                        ztColor = ztColorService.get(ztColor);
                        ztGoods.setColorid(jno.getString("colorid"));
                        ztGoods.setSpecificationsid(jno.get("specificationsid") == null ? "" : jno.get("specificationsid").toString());
                        ztGoods.setColor(ztColor.getTitle());//颜色名
                        ztGoods.setPrice(Double.valueOf(jno.get("goodsPrice").toString()));//商品价格
                        ztGoods.setOrigPrice(Double.valueOf(jno.get("price").toString()));//商品小计

                        //ztGoods.setFreight(Double.valueOf(jno.get("freight").toString()));//邮费

                        ztGoods.setCount(Integer.valueOf(jno.get("numCount").toString()));//数量

                        String img = ztColor.getImg();
                        if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                            ztGoods.setImg(myProps.getServerPath() + img);//颜色图
                        } else {
                            ztGoods.setImg(img);
                        }
                        if (jno.get("specificationsid") != null && StringUtils.isNotBlank(jno.get("specificationsid").toString()) && !"0".equals(jno.get("specificationsid").toString())) {

                            String specificationsid = jno.get("specificationsid").toString();
                            ZtSpecifications ztSpecifications = new ZtSpecifications();
                            ztSpecifications.setId(specificationsid);
                            ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                            ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());

                        }


                        ztGoodsList.add(ztGoods);
                    }
                    zo.setZtGoodsList(ztGoodsList);

                    Date orT = zo.getOrderTime();
                    zo.setTimestap(orT.getTime());

                }
            }
        }

        res.setResult(200L);
        res.setData(orderList);
        Render.renderString(response, res);
    }

    /**
     * 待发货列表
     */
    @ResponseBody
    @RequestMapping(value = "updateAddr")
    public void updateAddr(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");
        String order = jo.getString("order");
        String detailaddr = jo.getString("detailaddr");
        String name = jo.getString("name");
        String phone = jo.getString("phone");

        String province = "";
        if (jo.get("province") != null) {
            province = jo.get("province").toString();
        }
        String city = "";
        if (jo.get("city") != null) {
            city = jo.get("city").toString();
        }
        String county = "";
        if (jo.get("county") != null) {
            county = jo.get("county").toString();
        }

        String town = "";
        if (jo.get("town") != null) {
            town = jo.get("town").toString();
        }
        int townbid = 0;
        if (jo.get("townbid") != null) {
            townbid = Integer.valueOf(jo.get("townbid").toString());
        }
        int citybid = 0;
        if (jo.get("citybid") != null) {
            citybid = Integer.valueOf(jo.get("citybid").toString());
        }
        int provincebid = 0;
        if (jo.get("provincebid") != null) {
            provincebid = Integer.valueOf(jo.get("provincebid").toString());
        }
        int countybid = 0;
        if (jo.get("countybid") != null) {
            countybid = Integer.valueOf(jo.get("countybid").toString());
        }


        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);

        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setOrder(order);
        ztOrder.setZtAdmin(ztAdmin);
        ztOrder.setName(name);
        ztOrder.setPhone(phone);
        ztOrder.setAddr(province + city + county + " " + detailaddr);
        ztOrder.setDetailaddr(detailaddr);
        ztOrder.setProvince(province);
        ztOrder.setCity(city);
        ztOrder.setCounty(county);
        ztOrder.setTown(town);
        ztOrder.setTownbid(townbid);
        ztOrder.setCitybid(citybid);
        ztOrder.setProvincebid(provincebid);
        ztOrder.setCountybid(countybid);
        ztOrderService.updateAddr(ztOrder);

        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ztGoodsOrder.setOrder(order);
        ztGoodsOrder.setZtAdmin(ztAdmin);
        ztGoodsOrder.setName(name);
        ztGoodsOrder.setPhone(phone);
        ztGoodsOrder.setAddr(province + city + county + " " + detailaddr);
        ztGoodsOrder.setDetailaddr(detailaddr);
        ztGoodsOrder.setProvince(province);
        ztGoodsOrder.setCity(city);
        ztGoodsOrder.setCounty(county);
        ztGoodsOrder.setTown(ztOrder.getTown());
        ztGoodsOrder.setTownbid(ztOrder.getTownbid());
        ztGoodsOrder.setCitybid(ztOrder.getCitybid());
        ztGoodsOrder.setCountybid(ztOrder.getCountybid());
        ztGoodsOrder.setProvincebid(ztOrder.getProvincebid());
        ztGoodsOrderService.updateAddr(ztGoodsOrder);
        ResultObject res = new ResultObject();
        res.setResult(200L);
        Render.renderString(response, res);

    }

    /**
     * 待发货列表
     */
    @ResponseBody
    @RequestMapping(value = "yList")
    public void yList(HttpServletRequest request, HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");
        String pageNum = jo.getString("pageNum");
        String orderstatus = jo.getString("orderstatus");
        if (StringUtils.isBlank(pageNum)) {
            pageNum = "1";
        }

        ResultObject res = new ResultObject();
        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ztGoodsOrder.setZtAdmin(ztAdmin);
        ztGoodsOrder.setPageNum((Integer.valueOf(pageNum) - 1) * 15);

        ztGoodsOrder.setOrderstatus(orderstatus);

        List<ZtGoodsOrder> orderList = ztGoodsOrderService
                .findGhMh(ztGoodsOrder);

        if (orderList != null && orderList.size() > 0) {
            for (ZtGoodsOrder zo : orderList) {
                List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();
                ZtGoods ztGoods = zo.getZtGoods();
                ztGoods.setCount(zo.getNumCount());
                String img = ztGoods.getImg();
                if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                    ztGoods.setImg(myProps.getServerPath() + img);
                } else {
                    ztGoods.setImg(img);
                }
                ztGoods.setPrice(zo.getGoodsPrice());//商品价
                //ztGoods.setFreight(zo.getFreight()==null?0:zo.getFreight());

                ZtColor ztColor = new ZtColor();
                ztColor.setId(zo.getColorid());
                ztColor = ztColorService.get(ztColor);
                ztGoods.setColor(ztColor.getTitle());
                if (StringUtils.isNotBlank(zo.getSpecificationsid()) && !"0".equals(zo.getSpecificationsid())) {
                    ZtSpecifications ztSpecifications = new ZtSpecifications();
                    ztSpecifications.setId(zo.getSpecificationsid());
                    ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                    ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
                }

                //zo.setTotalPrice(new java.text.DecimalFormat("#.00").format(zo.getTotalPrice()+(zo.getBalance()==null?0:zo.getBalance())));

                ztGoods.setOrigPrice(Double.valueOf(new java.text.DecimalFormat("#.00").format(zo.getGoodsPrice() * zo.getNumCount())));//商品小计

                ztGoodsList.add(ztGoods);
                zo.setZtGoodsList(ztGoodsList);

                zo.setZtGoods(null);


            }
        }

        res.setResult(200L);
        res.setData(orderList);
        Render.renderString(response, res);
    }


    /**
     * 催订单发货
     */
    @ResponseBody
    @RequestMapping(value = "reminder")
    public void reminder(HttpServletRequest request, HttpServletResponse response) {
        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");
        String orderid = jo.getString("orderid");
        try {
            JedisUtils.set(adminid + orderid, "1", 60 * 60 * 3);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        ResultObject res = new ResultObject();

        res.setResult(200L);

        Render.renderString(response, res);
    }

    /**
     * 订单结算---------------------商品详情进入
     */
    @ResponseBody
    @RequestMapping(value = "toGoodsOrder")
    public void toGoodsOrder(HttpServletRequest request,
                             HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);
        ResultObject res = new ResultObject();
        JSONObject jno = JSONObject.parseObject(paramStr);
        String adminid = jno.getString("adminid");
        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ztAdmin = ztAdminService.get(ztAdmin);
        ZtGoods ztGoods = new ZtGoods();
        String level = StringUtils.isBlank(ztAdmin.getLevel()) ? "0" : ztAdmin.getLevel();
        ztGoods.setAdminLevel(level);
        String sku = "";
        ZtColor ztColor = new ZtColor();
        ztColor.setId(jno.getString("colorid"));    //颜色
        ztColor = ztColorService.get(ztColor);
        if (jno.get("specificationsid") != null && StringUtils.isNotBlank(jno.get("specificationsid").toString()) && !"0".equals(jno.get("specificationsid").toString())) {
            String specificationsid = jno.get("specificationsid").toString();
            ztGoods.setSpecificationsid(specificationsid);
            ZtSpecifications ztSpecifications = new ZtSpecifications();
            ztSpecifications.setId(specificationsid);
            ztSpecifications = ztSpecificationsService.get(ztSpecifications);
            sku = ztSpecifications.getSku();
            ztGoods.setCode(sku);
            ztGoods = ztGoodsService.getByCode(ztGoods);
            ztGoods.setColor(ztColor.getTitle());
            ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
        } else {
            ztGoods.setSpecificationsid("");
            sku = ztColor.getSku();
            ztGoods.setCode(sku);
            ztGoods = ztGoodsService.getByCode(ztGoods);
            ztGoods.setColor(ztColor.getTitle());//颜色名
        }
        // 验证商品是否可售
        if(ztGoods.getSpotid()==1) {

            if (!ProductPoolUtils.productSkuChec(sku)) {
                res.setResult(400L);
                res.setMsg("商品已暂停销售！");
                Render.renderString(response, res);
                return;
            }
        }
        ztGoods.setColorid(jno.getString("colorid"));
        int numCount = Integer.valueOf(jno.get("numCount").toString());

        if (!"0".equals(level)) {
            ztGoods.setPrice(ztGoods.getDiscountPrice());
        }

        BigDecimal b1 = new BigDecimal(ztGoods.getPrice());
        BigDecimal b2 = new BigDecimal(numCount);

        java.text.DecimalFormat df = new java.text.DecimalFormat("#.00");

        String dff = new java.text.DecimalFormat("#.00").format(b1.multiply(b2).doubleValue());

        ztGoods.setOrigPrice(Double.valueOf(dff)); //商品小计


        ztGoods.setCount(numCount);//数量

        String img = ztColor.getImg();
        if (img != null && StringUtils.isNotBlank(img) && !img.startsWith("http")) {
            ztGoods.setImg(myProps.getServerPath() + img);//颜色图
        } else {
            ztGoods.setImg(img);
        }

        List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();
        ztGoodsList.add(ztGoods);
        Map m = new HashMap();
        m.put("ztAdmin", ztAdmin);
        m.put("ztGoods", ztGoodsList);
        res.setData(m);
        res.setResult(200L);
        Render.renderString(response, res);
    }


    /**
     * 订单结算---------------------购物车详情进入
     */
    @ResponseBody
    @RequestMapping(value = "toTrolleyOrder")
    public void toTrolleyOrder(HttpServletRequest request,
                               HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);
        String adminid = "";

        JSONObject job = JSONObject.parseObject(paramStr);
        JSONArray jo = job.getJSONArray("trolleyids");
        List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();
        ResultObject res = new ResultObject();
        for (int i = 0; i < jo.size(); i++) {
            ZtTrolley ztTrolley = new ZtTrolley();
            ztTrolley.setId(jo.getString(i));
            ztTrolley = ztTrolleyService.get(ztTrolley);
            ZtGoods ztGoods = new ZtGoods();
            String level = StringUtils.isBlank(ztTrolley.getZtAdmin().getLevel()) ? "0" : ztTrolley.getZtAdmin().getLevel();

            ztGoods.setAdminLevel(level);
            String sku = "";
            ZtColor ztColor = new ZtColor();
            ztColor = ztTrolley.getZtColor();
            if (ztTrolley.getSpecifications() != null && StringUtils.isNotBlank(ztTrolley.getSpecifications().getId()) && !"0".equals(ztTrolley.getSpecifications().getId())) {
                String specificationsid = ztTrolley.getSpecifications().getId();
                ztGoods.setSpecificationsid(specificationsid);
                ZtSpecifications ztSpecifications = new ZtSpecifications();
                ztSpecifications.setId(specificationsid);
                ztSpecifications = ztSpecificationsService.get(ztSpecifications);

                sku = ztSpecifications.getSku();
                ztGoods.setCode(sku);
                ztGoods = ztGoodsService.getByCode(ztGoods);
                ztGoods.setColor(ztColor.getTitle());
                ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());

            } else {
                ztGoods.setSpecificationsid("");
                sku = ztColor.getSku();
                ztGoods.setCode(sku);
                ztGoods = ztGoodsService.getByCode(ztGoods);
                ztGoods.setColor(ztColor.getTitle());//颜色名
            }
            ztGoods.setTrolleyid(ztTrolley.getId());
            adminid = ztTrolley.getZtAdmin().getId();

            // 验证商品是否可售
            if(ztGoods.getSpotid()==1){
                if (!ProductPoolUtils.productSkuChec(sku)) {
                    res.setResult(400L);
                    res.setMsg("商品已暂停销售！");
                    Render.renderString(response, res);
                    return;
                }
            }

            if ("2".equals(ztGoods.getSjStatus()) & "4".equals(ztGoods.getSjStatus())) {
                res.setResult(400L);
                res.setMsg("商品已下架!");
                Render.renderString(response, res);
                return;
            }

            ztColor = ztTrolley.getZtColor();
            ztGoods.setColorid(ztColor.getId());

            if (!"0".equals(level)) {
                ztGoods.setPrice(ztGoods.getDiscountPrice());
            }
            //double fre=0d;
            int numCount = ztTrolley.getNumCount();

            BigDecimal b1 = new BigDecimal(ztGoods.getPrice());
            BigDecimal b2 = new BigDecimal(numCount);

            String dff = new java.text.DecimalFormat("#.00").format(b1.multiply(b2).doubleValue());

            ztGoods.setOrigPrice(Double.valueOf(dff)); //商品小计

            ztGoods.setCount(numCount);//数量

            String img = ztColor.getImg();
            if (img != null && StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                ztGoods.setImg(myProps.getServerPath() + img);//颜色图
            } else {
                ztGoods.setImg(img);
            }

            ztGoodsList.add(ztGoods);
        }

        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ztAdmin = ztAdminService.get(ztAdmin);

        Map m = new HashMap();
        m.put("ztAdmin", ztAdmin);
        m.put("ztGoods", ztGoodsList);
        res.setData(m);
        res.setResult(200L);
        Render.renderString(response, res);
    }

    /**
     * 全部订单列表
     */
    @ResponseBody
    @RequestMapping(value = "orderNum")
    public void orderNum(HttpServletRequest request,
                         HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);
        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");
        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setZtAdmin(ztAdmin);

        int orderNum = ztOrderService.getNum(ztOrder);

        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ztGoodsOrder.setZtAdmin(ztAdmin);
        Map map = new HashMap();
        int receivednum = ztGoodsOrderService.getNum(ztGoodsOrder);

        map.put("nopay", orderNum);
        map.put("receivednum", receivednum);

        ResultObject res = new ResultObject();
        res.setResult(200L);
        res.setData(map);
        Render.renderString(response, res);

    }

    /**
     * 全部订单列表
     */
    @ResponseBody
    @RequestMapping(value = "getGoodsAdminList")
    public void getGoodsAdminList(HttpServletRequest request,
                                  HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String goodsid = jo.getString("goodsid");
        ZtGoods ztGoods = new ZtGoods();
        ztGoods.setId(goodsid);
        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ztGoodsOrder.setZtGoods(ztGoods);
        List<Map> adminList = ztGoodsOrderService.getByGoods(ztGoodsOrder);
        for (Map m : adminList) {
            String name = m.get("name").toString();
            m.put("name", TTest.replaceNameX(name));
        }
        ResultObject res = new ResultObject();
        res.setResult(200L);
        res.setData(adminList);
        Render.renderString(response, res);
    }

    /**
     * 全部订单列表
     */
    @ResponseBody
    @RequestMapping(value = "allList")
    public void allList(HttpServletRequest request,
                        HttpServletResponse response) {

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String adminid = jo.getString("adminid");

        String pageNum = jo.get("pageNum").toString();
        String orderStatus = jo.getString("orderStatus");
        if (StringUtils.isBlank(pageNum)) {
            pageNum = "1";
        }

        ResultObject res = new ResultObject();
        ZtOrder ztOrder = new ZtOrder();
        ZtAdmin ztAdmin = new ZtAdmin();
        ztAdmin.setId(adminid);
        ztOrder.setZtAdmin(ztAdmin);
        ztOrder.setPageNum((Integer.valueOf(pageNum) - 1) * 15);
        ztOrder.setOrderstatus(orderStatus);

        List<ZtOrder> orderList = ztOrderService.findMh(ztOrder);

        List<Object> allOrderList = new ArrayList<Object>();

        if (orderList == null) {
            orderList = new ArrayList<ZtOrder>();
        }
        if (orderList.size() > 0) {

            for (ZtOrder zo : orderList) {

                if ("0".equals(zo.getOrderstatus()) || "4".equals(zo.getOrderstatus()) || "5".equals(zo.getOrderstatus()) || "1".equals(zo.getOrderstatus())) {//待付款 已取消订单
                    String goods = zo.getGoods();

                    if (StringUtils.isNotBlank(goods)) {
                        List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();

                        JSONArray goodsArr = JSONArray.parseArray(goods);

                        for (int i = 0; i < goodsArr.size(); i++) {
                            JSONObject jno = goodsArr.getJSONObject(i);

                            ZtGoods ztGoods = new ZtGoods();
                            ztGoods.setId(jno.getString("goodsid"));

                            ZtGoods ztg = ztGoodsService.get(ztGoods);
                            ztGoods.setTitle(ztg.getTitle());
                            ZtColor ztColor = new ZtColor();
                            ztColor.setId(jno.getString("colorid"));
                            ztColor = ztColorService.get(ztColor);
                            ztGoods.setColorid(jno.getString("colorid"));
                            ztGoods.setSpecificationsid(jno.get("specificationsid") == null ? "" : jno.get("specificationsid").toString());
                            ztGoods.setColor(ztColor.getTitle());//颜色名
                            ztGoods.setPrice(Double.valueOf(jno.get("goodsPrice").toString()));//商品价格
                            ztGoods.setOrigPrice(Double.valueOf(jno.get("price").toString()));//商品小计
                            //	ztGoods.setFreight(Double.valueOf(jno.get("freight").toString()));//邮费
                            ztGoods.setCount(Integer.valueOf(jno.get("numCount").toString()));//数量

                            String img = ztColor.getImg();
                            if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                                ztGoods.setImg(myProps.getServerPath() + img);//颜色图
                            } else {
                                ztGoods.setImg(img);
                            }
                            if (jno.get("specificationsid") != null && StringUtils.isNotBlank(jno.get("specificationsid").toString()) && !"0".equals(jno.get("specificationsid").toString())) {

                                String specificationsid = jno.get("specificationsid").toString();
                                ZtSpecifications ztSpecifications = new ZtSpecifications();
                                ztSpecifications.setId(specificationsid);
                                ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                                ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());

                            }


                            ztGoodsList.add(ztGoods);
                        }
                        zo.setZtGoodsList(ztGoodsList);

                        allOrderList.add(zo);

                    }
                    Date orT = zo.getOrderTime();
                    zo.setTimestap(orT.getTime());
                } else {

                    ZtGoodsOrder ztoder = new ZtGoodsOrder();
                    ztoder.setZtAdmin(ztAdmin);
                    ztoder.setOrder(zo.getOrder());
                    List<ZtGoodsOrder> goodsOrderList = ztGoodsOrderService.getListByOrder(ztoder);

                    if (orderList != null && orderList.size() > 0) {

                        for (ZtGoodsOrder zoz : goodsOrderList) {
                            List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();
                            ZtGoods ztGoods = zoz.getZtGoods();
                            ztGoods.setCount(zoz.getNumCount());
                            String img = ztGoods.getImg();
                            if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                                ztGoods.setImg(myProps.getServerPath() + img);
                            } else {
                                ztGoods.setImg(img);
                            }
                            ztGoods.setPrice(zoz.getGoodsPrice());//商品价
                            //ztGoods.setFreight(zoz.getFreight()==null?0:zoz.getFreight());

                            ZtColor ztColor = new ZtColor();
                            ztColor.setId(zoz.getColorid());
                            ztColor = ztColorService.get(ztColor);
                            ztGoods.setColor(ztColor.getTitle());
                            if (StringUtils.isNotBlank(zoz.getSpecificationsid()) && !"0".equals(zoz.getSpecificationsid())) {
                                ZtSpecifications ztSpecifications = new ZtSpecifications();
                                ztSpecifications.setId(zoz.getSpecificationsid());
                                ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                                ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
                            }
                            zoz.setTotalPrice(zoz.getTotalPrice() + (zoz.getBalance() == null ? 0 : zoz.getBalance()));
                            ztGoods.setOrigPrice(zoz.getTotalPrice());

                            ztGoodsList.add(ztGoods);
                            zoz.setZtGoodsList(ztGoodsList);
                            zoz.setZtGoods(null);

                            allOrderList.add(zoz);
                        }
                    }
                }

            }
        }

        res.setResult(200L);
        res.setData(allOrderList);
        Render.renderString(response, res);
    }

    /**
     * 已完成列表
     *//*
	@ResponseBody
	@RequestMapping(value = "successList")
	public void successList2(HttpServletRequest request,
			HttpServletResponse response) {

		String paramStr = CommonUtils.getParams(request);

		JSONObject jo = JSONObject.parseObject(paramStr);
		String adminid = jo.getString("adminid");
		String pageNum = jo.getString("pageNum");
		if (StringUtils.isBlank(pageNum)) {
			pageNum = "1";
		}

		ResultObject res = new ResultObject();
		ZtOrder ztOrder = new ZtOrder();
		ZtAdmin ztAdmin = new ZtAdmin();
		ztAdmin.setId(adminid);
		ztOrder.setZtAdmin(ztAdmin);
		ztOrder.setPageNum((Integer.valueOf(pageNum) - 1) * 15);

		List<ZtOrder> orderList = ztOrderService.findwc(ztOrder);
		if (orderList == null) {
			orderList = new ArrayList<ZtOrder>();
		}

		ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();

		ztGoodsOrder.setZtAdmin(ztAdmin);
		ztGoodsOrder.setPageNum((Integer.valueOf(pageNum) - 1) * 15);
		List<ZtGoodsOrder> ztGoodsOrderList = ztGoodsOrderService
				.findwc(ztGoodsOrder);
		// a.id,a.order,a.addr,a.phone,a.name,a.orderstatus,a.type,a.total_price
		if (ztGoodsOrderList == null) {
			ztGoodsOrderList = new ArrayList<ZtGoodsOrder>();
		}

		if (orderList.size() > 0) {
			for (ZtOrder zr : orderList) {
				ZtGoodsOrder zdr = new ZtGoodsOrder();
				zdr.setId(zr.getId());
				zdr.setOrder(zr.getOrder());
				zdr.setAddr(zr.getAddr());
				zdr.setPhone(zr.getPhone());
				zdr.setName(zr.getName());
				zdr.setOrderstatus(zr.getOrderstatus());
				zdr.setType(zr.getType());
				zdr.setTotalPrice(zr.getTotalPrice());
				zdr.setOrderTime(zr.getOrderTime());

				ztGoodsOrderList.add(zdr);
			}
		}
		ZtGoodsOrder sort = new ZtGoodsOrder();
		Collections.sort(ztGoodsOrderList, sort);

		res.setResult(200L);
		res.setData(ztGoodsOrderList);
		Render.renderString(response, res);
	}*/

    /**
     * 订单详情  *******************
     */
    @ResponseBody
    @RequestMapping(value = "orderDetail")
    public void orderDetail(HttpServletRequest request,
                            HttpServletResponse response) {
        String paramStr = CommonUtils.getParams(request);

        ResultObject res = new ResultObject();

        JSONObject jo = JSONObject.parseObject(paramStr);
        String orderid = jo.getString("orderid");
        String orderstatus = jo.get("orderstatus").toString();
        //0待付款订单，1是待发货订单   2是已发货订单  3是已完成订单   4已取消订单

        if ("0".equals(orderstatus) || "4".equals(orderstatus) || "5".equals(orderstatus)) {//待付款   已取消
            ZtOrder ztOrder = new ZtOrder();
            ztOrder.setId(orderid);
            ztOrder.setOrderstatus(orderstatus);

            ztOrder = ztOrderService.getOrder(ztOrder);

            double totalorigPrice = 0d;

            if (ztOrder != null) {

                String goods = ztOrder.getGoods();

                if (StringUtils.isNotBlank(goods)) {
                    List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();

                    JSONArray goodsArr = JSONArray.parseArray(goods);

                    for (int i = 0; i < goodsArr.size(); i++) {
                        JSONObject jno = goodsArr.getJSONObject(i);

                        ZtGoods ztGoods = new ZtGoods();
                        ztGoods.setId(jno.getString("goodsid"));

                        ZtGoods ztg = ztGoodsService.get(ztGoods);
                        ztGoods.setTitle(ztg.getTitle());
                        ZtColor ztColor = new ZtColor();
                        ztColor.setId(jno.getString("colorid"));
                        ztColor = ztColorService.get(ztColor);
                        ztGoods.setColorid(jno.getString("colorid"));
                        ztGoods.setColor(ztColor.getTitle());//颜色名
                        ztGoods.setPrice(Double.valueOf(jno.get("goodsPrice").toString()));//商品价格

                        double origPrice = Double.valueOf(jno.get("goodsPrice").toString()) * Integer.valueOf(jno.get("numCount").toString());
                        origPrice = Double.valueOf(new java.text.DecimalFormat("#.00").format(origPrice));
                        ztGoods.setOrigPrice(origPrice);//商品小计
                        totalorigPrice += origPrice;

                        //ztGoods.setFreight(Double.valueOf(jno.get("freight").toString()));//邮费
                        ztGoods.setCount(Integer.valueOf(jno.get("numCount").toString()));//数量

                        String img = ztColor.getImg();
                        if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                            ztGoods.setImg(myProps.getServerPath() + img);//颜色图
                        } else {
                            ztGoods.setImg(img);
                        }
                        if (jno.get("specificationsid") != null && StringUtils.isNotBlank(jno.get("specificationsid").toString()) && !"0".equals(jno.get("specificationsid").toString())) {

                            String specificationsid = jno.get("specificationsid").toString();
                            ZtSpecifications ztSpecifications = new ZtSpecifications();
                            ztSpecifications.setId(specificationsid);
                            ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                            ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
                            ztGoods.setSpecificationsid(specificationsid);

                        }

                        ztGoodsList.add(ztGoods);
                    }
                    ztOrder.setZtGoodsList(ztGoodsList);

                }
                Date orT = ztOrder.getOrderTime();
                ztOrder.setTimestap(orT.getTime());
            } else {
                ztOrder = new ZtOrder();
            }
            ztOrder.setOrigPrice(totalorigPrice);//商品总计

            res.setData(ztOrder);

        } else {
            ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
            ztGoodsOrder.setId(orderid);
            ztGoodsOrder.setOrderstatus(orderstatus);
            ztGoodsOrder = ztGoodsOrderService.getOrder(ztGoodsOrder);
            if (ztGoodsOrder != null) {
                List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();

                ZtGoods ztGoods = ztGoodsOrder.getZtGoods();
                ztGoods.setCount(ztGoodsOrder.getNumCount());
                String img = ztGoods.getImg();
                if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                    ztGoods.setImg(myProps.getServerPath() + img);
                }
                ztGoods.setPrice(ztGoodsOrder.getGoodsPrice());//商品价
                //ztGoods.setFreight(ztGoodsOrder.getFreight()==null?0:ztGoodsOrder.getFreight());

                ZtColor ztColor = new ZtColor();
                ztColor.setId(ztGoodsOrder.getColorid());
                ztColor = ztColorService.get(ztColor);
                ztGoods.setColor(ztColor.getTitle());
                if (StringUtils.isNotBlank(ztGoodsOrder.getSpecificationsid()) && !"0".equals(ztGoodsOrder.getSpecificationsid())) {
                    ZtSpecifications ztSpecifications = new ZtSpecifications();
                    ztSpecifications.setId(ztGoodsOrder.getSpecificationsid());
                    ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                    ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
                }

                //ztGoodsOrder.setTotalPrice(ztGoodsOrder.getTotalPrice()+(ztGoodsOrder.getBalance()==null?0:ztGoodsOrder.getBalance()));

                double origPrice = Double.valueOf(ztGoodsOrder.getGoodsPrice()) * Integer.valueOf(ztGoodsOrder.getNumCount());
                origPrice = Double.valueOf(new java.text.DecimalFormat("#.00").format(origPrice));

                ztGoods.setOrigPrice(origPrice);//商品小计

                ztGoodsList.add(ztGoods);
                ztGoodsOrder.setZtGoodsList(ztGoodsList);
                ztGoodsOrder.setOrigPrice(origPrice);
                ztGoodsOrder.setZtGoods(null);
            }
            res.setData(ztGoodsOrder);
        }

        res.setResult(200L);
        Render.renderString(response, res);
    }

    @ResponseBody
    @RequestMapping(value = "payOrderDetail")
    public void payOrderDetail(HttpServletRequest request,
                               HttpServletResponse response) {
        String paramStr = CommonUtils.getParams(request);
        ResultObject res = new ResultObject();
        JSONObject jo = JSONObject.parseObject(paramStr);
        String order = jo.getString("order");

        ZtOrder ztOrder = new ZtOrder();
        ztOrder.setOrder(order);

        ztOrder = ztOrderService.getByOrder(ztOrder);
        double origPrice = 0d;
        if (ztOrder != null) {
            String goods = ztOrder.getGoods();

            if (StringUtils.isNotBlank(goods)) {
                List<ZtGoods> ztGoodsList = new ArrayList<ZtGoods>();

                JSONArray goodsArr = JSONArray.parseArray(goods);

                for (int i = 0; i < goodsArr.size(); i++) {
                    JSONObject jno = goodsArr.getJSONObject(i);

                    ZtGoods ztGoods = new ZtGoods();
                    ztGoods.setId(jno.getString("goodsid"));

                    ZtGoods ztg = ztGoodsService.get(ztGoods);
                    ztGoods.setTitle(ztg.getTitle());
                    ZtColor ztColor = new ZtColor();
                    ztColor.setId(jno.getString("colorid"));
                    ztColor = ztColorService.get(ztColor);
                    ztGoods.setColorid(jno.getString("colorid"));
                    ztGoods.setColor(ztColor.getTitle());//颜色名
                    ztGoods.setPrice(Double.valueOf(jno.get("goodsPrice").toString()));//商品价格
                    ztGoods.setOrigPrice(Double.valueOf(jno.get("price").toString()));//商品小计
                    //ztGoods.setFreight(Double.valueOf(jno.get("freight").toString()));//邮费
                    ztGoods.setCount(Integer.valueOf(jno.get("numCount").toString()));//数量
                    origPrice += ztGoods.getOrigPrice();
                    String img = ztColor.getImg();
                    if (StringUtils.isNotBlank(img) && !img.startsWith("http")) {
                        ztGoods.setImg(myProps.getServerPath() + img);//颜色图
                    } else {
                        ztGoods.setImg(img);//颜色图
                    }
                    if (jno.get("specificationsid") != null && StringUtils.isNotBlank(jno.get("specificationsid").toString()) && !"0".equals(jno.get("specificationsid").toString())) {

                        String specificationsid = jno.get("specificationsid").toString();
                        ZtSpecifications ztSpecifications = new ZtSpecifications();
                        ztSpecifications.setId(specificationsid);
                        ztSpecifications = ztSpecificationsService.get(ztSpecifications);
                        ztGoods.setColor(ztGoods.getColor() + "、" + ztSpecifications.getName());
                        ztGoods.setSpecificationsid(specificationsid);

                    }


                    ztGoodsList.add(ztGoods);
                }
                ztOrder.setZtGoodsList(ztGoodsList);
            }
        } else {
            ztOrder = new ZtOrder();
        }
        ztOrder.setOrigPrice(origPrice);

        Date orT = ztOrder.getOrderTime();
        ztOrder.setTimestap(orT.getTime());

        res.setData(ztOrder);
        res.setResult(200L);
        Render.renderString(response, res);
    }

    /**
     * 查看物流信息
     */
    @ResponseBody
    @RequestMapping(value = "getGoodsLogistics")
    public void getGoodsLogistics(HttpServletRequest request,
                                  HttpServletResponse response) {
        ResultObject res = new ResultObject();

        String paramStr = CommonUtils.getParams(request);

        JSONObject jo = JSONObject.parseObject(paramStr);
        String logistics = jo.getString("logistics");
        String logisticsCode = jo.getString("logisticsCode");

        String orderid = jo.getString("orderid");//订单id

        ZtGoodsOrder ztGoodsOrder = new ZtGoodsOrder();
        ztGoodsOrder.setId(orderid);
        ztGoodsOrder = ztGoodsOrderService.get(ztGoodsOrder);
        if (ztGoodsOrder != null && StringUtils.isNotBlank(ztGoodsOrder.getId())) {
            int spotid = ztGoodsOrder.getSpotid();
            if (spotid == 1) {   //京东
                String orderinfo = checkOrderinfo(ztGoodsOrder);
                String orderTrack = ProductPoolUtils.orderTrack(orderinfo);//
                res.setResult(200L);
                res.setMsg("1");
                res.setData(orderTrack);
                Render.renderString(response, res);
                return;
            }
        }

        String logisticsName = ZtWL.getKey(logisticsCode);

        KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI();
        String result = "";
        try {
            // result = api.getOrderTracesByJson("ZTO", "218757329343");
            result = api.getOrderTracesByJson(logisticsCode, logistics);
            JSONObject j = JSONObject.parseObject(result);
            j.put("ShipperName", logisticsName);
            result = j.toJSONString();

        } catch (Exception ex) {
            ex.printStackTrace();
            res.setResult(400L);
            Render.renderString(response, res);
            return;
        }

        res.setResult(200L);
        res.setMsg("0");
        res.setData(result);
        Render.renderString(response, res);
		
		/*response.reset();
		response.setContentType("application/json");
		response.setCharacterEncoding("utf-8");
		try {
			response.getWriter().print(result);
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
    }

    /**
     *  校验是否有子订单
     * @param ztGoodsOrder
     * @return
     */
    private String checkOrderinfo(ZtGoodsOrder ztGoodsOrder) {
        Long skus = Long.valueOf(ztGoodsOrder.getSku());
        String jdOrder = "";
        JSONObject info = ProductPoolUtils.findProductOrderInfo(ztGoodsOrder.getChannelorder());
        if (info != null) {
            OnOrderVo onOrderVo = null;
            POrderVo pOrderVo = null;
            try {
                onOrderVo = info.getObject("result", OnOrderVo.class);
            } catch (Exception e) {
                //e.printStackTrace();
            }
            try {
                pOrderVo = info.getObject("result", POrderVo.class);
            } catch (Exception e) {
                //e.printStackTrace();
            }
            if (onOrderVo != null) {
                List<OnOrderVo.COrderBean> cOrder = onOrderVo.getCOrder();
                for (OnOrderVo.COrderBean bean : cOrder) {
                    for (OnOrderVo.COrderBean.SkuBeanX sku : bean.getSku()) {
                        if (sku.getSkuId() == skus) {
                            jdOrder += bean.getJdOrderId();
                        }
                    }
                }
            }
            if (pOrderVo != null) {
                jdOrder += ztGoodsOrder.getChannelorder();
            }
        }
        return jdOrder;
    }

    /**
     * 查看物流信息
     */
    @ResponseBody
    @RequestMapping(value = "getLogisticsAllInfo")
    public void getLogisticsAllInfo(HttpServletRequest request,
                                    HttpServletResponse response) {

        ResultObject res = new ResultObject();

        res.setResult(200L);
        res.setData(ZtWL.toList());
        Render.renderString(response, res);
    }
	/*if (StringUtils.isNotBlank(ztOr.getOrderstatus())
	&& !"3".equals(ztOr.getOrderstatus())) {
String logistics = ztOr.getLogistics();
String logisticsCode = ztOr.getLogisticsCode();

if (StringUtils.isNotBlank(logistics)
		&& StringUtils.isNotBlank(logisticsCode)) {
	try {
		KdniaoTrackQueryAPI api = new KdniaoTrackQueryAPI();
		String result = api.getOrderTracesByJson(logistics,
				logisticsCode);

		String ps = CommonUtils.getParams(request);
		JSONObject job = JSONObject.parseObject(ps);
		String state = job.getString("State");
		if ("3".equals(state)) {
			ztOr.setOrderstatus("3");
			ztGoodsOrderService.save(ztOr);
		}
	} catch (Exception ex) {
		ex.printStackTrace();

	}
}
}*/

    /**
     * 明细  支出
     * @param
     * @param
     * @param
     */
    public void forBalance(ZtGoodsOrder ztGoodsOrder){
        double balance=ztGoodsOrder.getBalance();
        double total = ztGoodsOrder.getTotalPrice();
        List<ZtFinancial> list = new ArrayList<>();
        if(balance>0D){
            ZtFinancial ztFinancial=new ZtFinancial();
            ztFinancial.setAudit("2");
            ztFinancial.setType("5");
            ztFinancial.setContent("积分支付退款-"+ztGoodsOrder.getZtGoods().getTitle());
            ztFinancial.setZtAdmin(ztGoodsOrder.getZtAdmin());
            ztFinancial.setPricestr("+￥"+balance);
            ztFinancial.setPrice(balance);
            ztFinancial.setCreateDate(new Date());
            ztFinancial.setUsername(ztGoodsOrder.getZtAdmin().getUsername());
            ztFinancial.setHeadimgurl(ztGoodsOrder.getZtAdmin().getHeadimgurl());
            ztFinancial.setPhone(ztGoodsOrder.getZtAdmin().getPhone());
            ztFinancial.setZtGoods(ztGoodsOrder.getZtGoods());
            ztFinancial.setStatus("0");
            ztFinancial.setOperation("系统");
            list.add(ztFinancial);
        }
        if(total>0D){
            ZtFinancial ztFinancial=new ZtFinancial();
            ztFinancial.setAudit("2");
            ztFinancial.setType("5");
            ztFinancial.setContent("微信支付退款-"+ztGoodsOrder.getZtGoods().getTitle());
            ztFinancial.setZtAdmin(ztGoodsOrder.getZtAdmin());
            ztFinancial.setPricestr("+￥"+ztGoodsOrder.getTotalPrice());
            ztFinancial.setPrice(ztGoodsOrder.getTotalPrice());
            ztFinancial.setCreateDate(new Date());
            ztFinancial.setUsername(ztGoodsOrder.getZtAdmin().getUsername());
            ztFinancial.setHeadimgurl(ztGoodsOrder.getZtAdmin().getHeadimgurl());
            ztFinancial.setPhone(ztGoodsOrder.getZtAdmin().getPhone());
            ztFinancial.setZtGoods(ztGoodsOrder.getZtGoods());
            ztFinancial.setStatus("0");
            ztFinancial.setOperation("系统");
            list.add(ztFinancial);
        }
        if(list.size()>0){
            ztFinancialService.insertBatch(list);
        }
    }
}